
zm.ready(function() {
    zm("#submit_response").click(function() {
// find title and decription form
        var idSurvey = zm('.header-form').attr("idsurvey");
        var idUser = 1;
        var response = new Response(idUser);
        // find question form

        zm('.question-answer').each(function() {
            var idQuestion = zm(this).attr("idquestion");
            var type = zm(this).find('.answer').attr("typeanswer");
            var require = zm(this).find('.require').attr("requirement");
            if (type === singleselection) {
                var answers = "";
                zm(this).find('.answer .answer-option').each(function() {
                    var option = zm(this).find('input[type="radio"]').attr("checked");
                    if (option) {
                        answers += "1,";
                    }
                    else {
                        answers += "0,";
                    }

                });
            }
            if (type === multichoice) {
                var answers = "";
                zm(this).find('.answer .answer-option').each(function() {
                    var option = zm(this).find('input[type="checkbox"]').attr("checked");
                    if (option) {
                        answers += "1,";
                    }
                    else {
                        answers += "0,";
                    }

                });
            }
            if (type === multiline) {
                zm(this).find('textarea').each(function() {
                    answers = zm(this).val();
                });
            }
            if (type === singleline) {
                zm(this).find('input[type="text"]').each(function() {
                    answers = zm(this).val();
                });
            }
            var answerItem = new AnswerItem(type, idQuestion, answers, require);
            response.addAnswers(answerItem);
        });
        var JSONResponse = zm.serialize(response);
        console.log(JSONResponse);
        ajaxSubmitResponse(idSurvey, JSONResponse);
    });
});

